#include "ScaleCalculator.h"
#include <TGS/GeoMath2.0/Envelope.h>
#include <cmath>

namespace TGS{
namespace MapControl{


ScaleCalculator::ScaleCalculator( double dpi)
    : _dpi( dpi )
{}

ScaleCalculator::~ScaleCalculator()
{}

void ScaleCalculator::setDpi( double dpi )
{
	_dpi = dpi;
}
double ScaleCalculator::dpi()
{
	return _dpi;
}

double ScaleCalculator::calculate( const Envelope &mapExtent, int canvasWidth )
{
	const double inch2MeterFactor = 1.0 / 39.3700787;
	const double meter2Centimeter = 100;
	double delta = mapExtent.getMaxX() - mapExtent.getMinX();

	double scale = delta / ((double)canvasWidth / _dpi * inch2MeterFactor * meter2Centimeter);
	return scale;
}

}//MapControl
}//TGS